<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>使用$.grep()工具函数筛选数组中的元素</title>
<script src="../lib/jquery-2.0.3.min.js" type="text/javascript"></script>
<style type="text/css">
	body{font-size:13px}
	div{margin:5px;padding:10px;border:solid 1px #666;background-color:#666;width:300px;}
</style>
<script type="text/javascript">
	$(function(){
		var strTmp = "筛选前数据";
		var arrNum=[2,8,3,7,4,9,3,10,9,7,21];
		var arrGet = $.grep(arrNum,function(ele,index){
			return ele>5 && index<8;//元素值大于5且序号小于8
		});
		strTmp +=arrNum.join();
		strTmp +="<br/><br/>筛选后数据:";
		strTmp +=arrGet.join();
		$("#divTip").append(strTmp); 
	})
</script>
</head>
<body>
	<div id="divTip"></div>
</body>
</html>